<template>   
    <div ref="parent" class="gamemap">  
        <canvas ref="canvas" tabindex="0"></canvas> 
    </div>
</template>

<script>
import { GameMap } from '@/assets/scripts/GameMap';  //前端标签在mdn里搜
import { ref, onMounted  } from 'vue'; // vue里定义变量要用ref, onMounted组件挂载完后执行操作函数
import { useStore } from 'vuex';

export default {
    setup() {
        const store = useStore();
        let parent = ref(null);
        let canvas = ref(null);

        onMounted(() => {
            store.commit(
                "updateGameObject",
                new GameMap(canvas.value.getContext('2d'), parent.value, store),
            );
        });

        return {
            parent,
            canvas
        }
    }
}
</script>

<style scoped>
div.gamemap {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-content: center;
}
</style>